var http = require('http')

var server = http.createServer()

server.on('request',function (res, req) {
    var url = res.url;
    if (url == '/'){
        req.end('index page')
    } else if(url == '/login'){
        req.end('login page')
    }else if(url == '/product'){
        var products = [{
            name: '苹果 X',
            price: 8888
        },
            {
                name: '菠萝 X',
                price: 5000
            },
            {
                name: '小辣椒 X',
                price: 1999
            }
        ]
        req.end(JSON.stringify(products))
    }else{
        req.end('404 not found')
    }
})

server.listen(3000, function (res) {
    console.log(res)
})